package com.example.springbootcondition.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

/**
 * @program: springboot1
 * @description:
 * @author: zhanghz001
 * @create: 2020-12-08 16:05
 **/
public class ClassCondition implements Condition {
    /**
     * @param conditionContext      获取上下文对象,获取环境对象,ioc容器,classloader对象
     * @param annotatedTypeMetadata 注解原对象,可以用于获取注解定义的属性值
     * @return
     */
    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        boolean flag = true;
        try {
            // Jedis
            Map<String, Object> map = annotatedTypeMetadata.getAnnotationAttributes(
                    "com.example.springbootcondition.condition.ConditionOnClass");
            String[] className = (String[]) map.get("value");
            for (String str : className) {
                Class<?> clazz = Class.forName(str);
            }
        } catch (Exception e) {
            flag = false;
        } finally {
        }
        return flag;
    }
}
